<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ticker">
              <a-input v-model="model.ticker" placeholder="请输入币种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易所" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ex">
              <a-input v-model="model.ex" placeholder="请输入交易所"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="收盘价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="close">
              <a-input-number v-model="model.close" placeholder="请输入收盘价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="开盘价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="open">
              <a-input-number v-model="model.open" placeholder="请输入开盘价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最高价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="high">
              <a-input-number v-model="model.high" placeholder="请输入最高价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="最低价" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="low">
              <a-input-number v-model="model.low" placeholder="请输入最低价" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="time">
              <j-date placeholder="请选择时间" v-model="model.time"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成交量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="volume">
              <a-input-number v-model="model.volume" placeholder="请输入成交量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="现在时间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="timenow">
              <j-date placeholder="请选择现在时间" v-model="model.timenow"  style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="时间区间" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="interval">
              <a-input-number v-model="model.interval" placeholder="请输入时间区间" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="头寸大小 " :labelCol="labelCol" :wrapperCol="wrapperCol" prop="positionSize">
              <a-input-number v-model="model.positionSize" placeholder="请输入头寸大小 " style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买卖方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="action">
              <a-input v-model="model.action" placeholder="请输入买卖方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="
合同" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="contracts">
              <a-input-number v-model="model.contracts" placeholder="请输入
合同" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="price">
              <a-input-number v-model="model.price" placeholder="请输入价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易账号id" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="trdateId">
              <a-input-number v-model="model.trdateId" placeholder="请输入交易账号id" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市场方向" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketPosition">
              <a-input v-model="model.marketPosition" placeholder="请输入市场方向"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="市场方向价格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="marketPositionSize">
              <a-input-number v-model="model.marketPositionSize" placeholder="请输入市场方向价格" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易所" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="exchange">
              <a-input v-model="model.exchange" placeholder="请输入交易所"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="杠杆倍数" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="lever">
              <a-input-number v-model="model.lever" placeholder="请输入杠杆倍数" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="保证金模式" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="tdMode">
              <a-input v-model="model.tdMode" placeholder="请输入保证金模式"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="symbol">
              <a-input v-model="model.symbol" placeholder="请输入币种"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="交易类型（marker，limit)" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="ordType">
              <a-input v-model="model.ordType" placeholder="请输入交易类型（marker，limit)"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="成交数量" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amount">
              <a-input-number v-model="model.amount" placeholder="请输入成交数量" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TvcTradeDockingForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/trade/tvcTradeDocking/add",
          edit: "/trade/tvcTradeDocking/edit",
          queryById: "/trade/tvcTradeDocking/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>